import { Component, OnInit, Input } from '@angular/core'
import { BaseInfoComponent } from '@shared/components/base-info/base-info.component'
import { ITransInfo } from '@shared/interfaces/task'
import { I18NService } from '@core'
import { Router, ActivatedRoute } from '@angular/router'
import { TitleService } from '@delon/theme'
import { PageService } from '@shared/services/page.service'
import { DetailBaseClass } from '@shared/classes/DetailBaseClass'
import { AmtFormatPipe } from '@shared/filters/amt-format.pipe'
import { IBaseInfoColumn } from '@shared/interfaces/baseInfo'

@Component({
  selector: 'app-task-refund-info',
  templateUrl: './refund-info.component.html',
})
export class TaskRefundInfoComponent extends DetailBaseClass<ITransInfo> implements OnInit {
  @Input() transInfo: ITransInfo

  firstColumns: IBaseInfoColumn[]

  constructor(
    public i18n: I18NService,
    public router: Router,
    public route: ActivatedRoute,
    public titleService: TitleService,
    public pageService: PageService,
    private amtFormatPipe: AmtFormatPipe,
  ) {
    super(pageService)
  }

  ngOnInit() {
    this.detailData = this.transInfo
    this.initFirstColumns()
    this.initColumns()
  }

  initFirstColumns(): void {
    const { txamt, currency } = this.detailData
    const refundAmt = this.amtFormatPipe.transformPrice(parseFloat(txamt), currency, '-')
    this.firstColumns = [
      {
        span: 4,
        index: '',
        label: '退款金额',
        labelI18n: 'TRADE.REFUND.AMT',
        asyncValue: refundAmt,
      },
      {
        span: 20,
        index: 'refundDetail',
        label: '退款说明',
        labelI18n: 'TRADE.REFUND.REMARK',
      },
    ]
  }
}
